package cn.com.generaldata.os.service.common;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import javax.annotation.PostConstruct;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.entity.Record;
import org.nutz.json.Json;
import org.nutz.lang.Files;
import org.nutz.lang.Lang;
import org.nutz.lang.Mirror;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.generaldata.jsme_indicator_system.entity.ReportInputTitle;
import cn.com.generaldata.jsme_indicator_system.entity.ReportTypeIndicator;
import cn.com.generaldata.jsme_indicator_system.entity.ReportTypeNz;
import cn.com.generaldata.jsme_indicator_system.util.Constants;
import cn.com.generaldata.jsme_indicator_system.util.Constants.ReportStyle;
import cn.com.generaldata.jsme_indicator_system.vo.reportdesigner.ReportCell;
import cn.com.generaldata.jsme_indicator_system.vo.reportdesigner.ReportExcelSectionVO;
import cn.com.generaldata.jsme_indicator_system.vo.reportdesigner.ReportExcelSectionVO.ReportExcelInputInfo;
import cn.com.generaldata.jsme_indicator_system.vo.reportdesigner.ReportFooterCell;
import cn.com.generaldata.jsme_indicator_system.vo.reportdesigner.ReportTemplateInfo;
import cn.com.generaldata.os.dao.intf.BaseDAOInterface;
import cn.com.generaldata.os.newpojo.ReportType;
import cn.com.generaldata.os.pojo.ReportDetail;
import cn.com.generaldata.os.pojo.User;
import cn.com.generaldata.os.pojo.mvc.Row;
import cn.com.generaldata.os.util.Beetls;
import cn.com.generaldata.os.zip.ZipCompressor;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

@Service
public class ReportTemplateService {

	private static Logger log = LoggerFactory.getLogger(ReportTemplateService.class);
	@Autowired
	private Dao indicatorSystemDao;
	private BaseDAOInterface<User> userDAO;
	private Map<String, String> officeCode;
	private BaseDAOInterface<cn.com.generaldata.os.pojo.Report> reportDAO;
	private BaseDAOInterface<ReportDetail> reportDetailDAO;
	private final Mirror<Row> rowMirror = Mirror.me(Row.class);

	public void setUserDAO(BaseDAOInterface<User> userDAO) {
		this.userDAO = userDAO;
	}

	private ReportExcelTemplateBuilder reportExcelTemplateBuilder;
	private final AtomicInteger dirCount = new AtomicInteger(1);
	private final Properties properties = new Properties();

	public void setReportDAO(BaseDAOInterface<cn.com.generaldata.os.pojo.Report> reportDAO) {
		this.reportDAO = reportDAO;
	}

	public void setReportDetailDAO(BaseDAOInterface<ReportDetail> reportDetailDAO) {
		this.reportDetailDAO = reportDetailDAO;
	}

	public void setReportExcelTemplateBuilder(ReportExcelTemplateBuilder reportExcelTemplateBuilder) {
		this.reportExcelTemplateBuilder = reportExcelTemplateBuilder;
	}

	@PostConstruct
	public void init() {
		officeCode = Maps.newHashMap();
		List<Record> offices = indicatorSystemDao.query("t_system_codedic", Cnd.where("section", "=", "10022"));
		for (Record record : offices) {
			officeCode.put(record.getString("code"), record.getString("code_name"));
		}

		java.io.InputStream inputstream = getClass().getResourceAsStream("/fileupload.properties");
		try {
			properties.load(inputstream);
		} catch (Exception ex) {
			log.error("加载配置文件出错", ex);
		}
		String path = properties.getProperty("excelDownPath").trim();
		Files.clearDir(new File(path));
	}

	public String renderCreateTemplate(String reportTypeId, cn.com.generaldata.os.pojo.mvc.Report report, User user) {
		// Beetls.renderString(templateString, model)
		ReportTypeNz reportType = indicatorSystemDao.fetch(ReportTypeNz.class, reportTypeId);
		ReportTemplateInfo reportInfo = Json.fromJson(ReportTemplateInfo.class, reportType.getReportInfo());
		List<Row> rows = null;
		// 单元格报表按200行初始化，行式报表只初使化一行
		int initRows = reportType.getDataType().intValue() == 1 ? 200 : 1;
		if (report.getRows() == null || report.getRows().isEmpty()) {
			rows = Lists.newArrayList();
			for (int i = 0; i < initRows; i++) {
				rows.add(new Row());
			}
		} else {
			rows = report.getRows();
		}
		String template = reportType.getTemplate();
		Map model = ImmutableMap.of("rows", rows, "reportType", reportType, "officeCode", officeCode, "user", user,
				"report", report);
		if (Constants.ReportStyle.ROW.getValue() == reportType.getDataType().intValue()) {
			if (!reportInfo.getTableBodyAgg().isEmpty()) {
				model = Maps.newHashMap(model);
				model.put("footRows", ImmutableList.of(new Row()));
			}
		}
		return Beetls.renderString(template, model);
	}

	public cn.com.generaldata.os.pojo.mvc.Report replaceIndicator(ReportType rType,
			cn.com.generaldata.os.pojo.mvc.Report report, Set<String> indicators) {
		Cnd cnd = Cnd.where("reportTypeId", "=", report.getReportTypeId());
		List<ReportTypeIndicator> indicatorRel = indicatorSystemDao.query(ReportTypeIndicator.class, cnd);
		//列式
		if (rType.getDataType().intValue() == Constants.ReportStyle.CELL.getValue())
			report = setCellReport(report, indicatorRel, indicators);
		else
			report = setRowReport(report, indicatorRel, indicators);
		return report;
	}

	public cn.com.generaldata.os.pojo.mvc.Report setRowReport(cn.com.generaldata.os.pojo.mvc.Report report,
			List<ReportTypeIndicator> indicatorRel, Set<String> indicators) {
		List<Row> rows = report.getRows();
		for (ReportTypeIndicator indicator : indicatorRel) {
			if (indicators.contains(indicator.getIndicatorId().toString())) {
				for (Row rowIndex : rows) {
					String fieldName = String.format("f%d", indicator.getTheColumn());
					rowMirror.setValue(rowIndex, fieldName, "");
				}
			}
		}
		return report;
	}

	public cn.com.generaldata.os.pojo.mvc.Report setCellReport(cn.com.generaldata.os.pojo.mvc.Report report,
			List<ReportTypeIndicator> indicatorRel, Set<String> indicators) {
		List<Row> rows = report.getRows();
		for (ReportTypeIndicator indicator : indicatorRel) {
			if (indicators.contains(indicator.getIndicatorId().toString())) {
				Integer row = indicator.getRow();
				for (Row rowIndex : rows) {
					//是屏蔽那行
					if (row == rowIndex.getRowIndex()) {
						String fieldName = String.format("f%d", indicator.getTheColumn());
						rowMirror.setValue(rowIndex, fieldName, "");
					}
				}
			}
		}
		return report;
	}

	public String renderUpdateTemplate(String reportTypeId, List<Row> rows,
			cn.com.generaldata.os.pojo.mvc.Report report, User user) {
		// Beetls.renderString(templateString, model)
		ReportTypeNz reportType = indicatorSystemDao.fetch(ReportTypeNz.class, reportTypeId);
		ReportTemplateInfo reportInfo = Json.fromJson(ReportTemplateInfo.class, reportType.getReportInfo());
		String template = reportType.getTemplate();
		int initRows = reportType.getDataType().intValue() == 1 ? 200 : 1;

		// List<Row> rows = Lists.newArrayList();
		for (int i = rows.size(); i < initRows; i++) {
			rows.add(new Row());
		}
		Map<String, Object> model = Maps.newHashMap();
		model.put("rows", rows);
		model.put("officeCode", officeCode);
		model.put("reportType", reportType);
		model.put("report", report);
		model.put("user", user);

		if (Constants.ReportStyle.ROW.getValue() == reportType.getDataType().intValue()) {
			if (!reportInfo.getTableBodyAgg().isEmpty()) {
				model = Maps.newHashMap(model);
				Row lastRow = rows.get(rows.size() - 1);
				model.put("footRows", ImmutableList.of(lastRow));
			}
		}
		return Beetls.renderString(template, model);
	}

	public String generalFile(cn.com.generaldata.os.pojo.Report report, String folder, String areaId) {
		String fileName = "";
		
		ReportTypeNz reportType = indicatorSystemDao.fetch(ReportTypeNz.class, report.getReportTypeId());
		
		if ("0".equals(report.getReportTimetype())) {
			fileName = report.getReportUnit() + report.getReportYear() + "年" + report.getMonth() + "月"
					+ reportType.getTypeNo() + "_" + report.getReportType();
		} else if ("1".equals(report.getReportTimetype())) {
			if ("2".equals(report.getReportYearTime())) {
				fileName = report.getReportUnit() + report.getReportYear() + "年" + reportType.getTypeNo() + "_" + report.getReportType();
			} else if ("1".equals(report.getReportYearTime())) {
				fileName = report.getReportUnit() + report.getReportYear() + "半年报" + reportType.getTypeNo() + "_" + report.getReportType();
			} else {
				fileName = report.getReportUnit() + report.getReportYear() + "快报" + reportType.getTypeNo() + "_" + report.getReportType();
			}
		} else if ("2".equals(report.getReportTimetype())) {
			fileName = report.getReportUnit() + report.getReportYear() + report.getReportQuarter()
					+ reportType.getTypeNo() + "_" + report.getReportType();
		}

		
		String reportInfo = reportType.getReportInfo();
		cn.com.generaldata.jsme_indicator_system.vo.reportdesigner.ReportTemplateInfo reportDesigner = Json.fromJson(
				cn.com.generaldata.jsme_indicator_system.vo.reportdesigner.ReportTemplateInfo.class, reportInfo);
		File file = reportExcelTemplateBuilder.buildReportExcel(reportType.getDataType(), report, reportDesigner,
				properties.getProperty("excelDownPath").trim() + folder, fileName, areaId);
		String path = properties.getProperty("excelDownPath").trim() + folder + File.separator + fileName + ".xls"; // 路径是存文件的路径
		return path;
	}

	/**
	 * 生成excel
	 * 
	 * @param list
	 */
	public String generalExcel(List<String> ids, String areaId) {
		if (ids != null && ids.size() > 0) {
			//			String folder = String.valueOf(dirCount.getAndIncrement());
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
			String folder = String.valueOf(sdf.format(new Date()));
			for (String reportId : ids) {
				cn.com.generaldata.os.pojo.Report report = reportDAO.get(cn.com.generaldata.os.pojo.Report.class,
						reportId);
				//				Filter filter = new Filter();
				//				filter.addRule(new FilterRule(FilterConstant.EQUAL, "report.id", reportId));
				//				filter.setOrder(FilterConstant.DESC);
				//				filter.setSortBy("rowIndex");
				//				List<ReportDetail> rdList = reportDetailDAO.find(ReportDetail.class, filter, null);
				//				Set set = new HashSet(rdList);
				//				report.setReportDetails(set);
				generalFile(report, folder, areaId);
			}
			String zipPath = folder + ".zip";
			ZipCompressor zc = new ZipCompressor(properties.getProperty("excelDownPath").trim() + zipPath);
			zc.compress(properties.getProperty("excelDownPath").trim() + folder); // 压缩一个文件夹
			return zipPath;
		}
		return null;
	}

	/**
	 * 详细报表详情页面.
	 * 
	 * @param reportTypeId
	 * @param rows
	 * @param report
	 * @param user
	 * @return
	 */
	public String renderDetailTemplate(String reportTypeId, cn.com.generaldata.os.pojo.mvc.Report report, User user) {
		String updateTemplate = renderUpdateTemplate(reportTypeId, report.getRows(), report, user);

		Document doc = Jsoup.parseBodyFragment(updateTemplate);

		Elements textFields = doc.select("#report-body td input[type=text]");
		textFields.addAll(doc.select("#report-foot td input[type=text]"));

		for (Element textField : textFields) {
			String val = textField.val();
			textField.parent().empty().text(val);
		}

		Elements selectContainers = doc.select("#report-body td[indicator-input-type=select]");
		for (Element selectContainer : selectContainers) {
			String val = selectContainer.select("select").val();
			selectContainer.empty().text(val);
		}

		Elements radioContainers = doc.select("#report-body td[indicator-input-type=radio]");
		for (Element radioContainer : radioContainers) {
			String val = radioContainer.select("input[checked]").val();
			radioContainer.empty().text(val);
		}

		Elements checkboxContainers = doc.select("#report-body td[indicator-input-type=checkbox]");
		for (Element checkboxContainer : checkboxContainers) {

			Elements checkeds = checkboxContainer.select("input[checked]");
			String checkedVal = "";
			for (Element checked : checkeds) {
				checkedVal += checked.val() + " ";
			}

			checkboxContainer.empty().text(checkedVal);
		}

		Element addRowBtn = doc.getElementById("#add-report-body-row-btn");
		if (addRowBtn != null) {
			addRowBtn.parent().remove();
		}

		Document fullDoc = Jsoup.parseBodyFragment(reportExcelHtmlTemp);
		fullDoc.select("html").first().appendChild(doc.body());
		return fullDoc.outerHtml();
	}

	/**
	 * 详细报表详情页面.
	 * 
	 * @param reportTypeId
	 * @param rows
	 * @param report
	 * @param user
	 * @return
	 */
	public String renderDetailTemplate1(String reportTypeId, cn.com.generaldata.os.pojo.mvc.Report report, User user) {
		String updateTemplate = renderUpdateTemplate(reportTypeId, report.getRows(), report, user);

		Document doc = Jsoup.parseBodyFragment(updateTemplate);

		Elements textFields = doc.select("#report-body td input[type=text]");
		textFields.addAll(doc.select("#report-foot td input[type=text]"));

		for (Element textField : textFields) {
			String val = textField.val();
			textField.parent().empty().text(val);
		}

		Elements selectContainers = doc.select("#report-body td[indicator-input-type=select]");
		for (Element selectContainer : selectContainers) {
			String val = selectContainer.select("select").val();
			selectContainer.empty().text(val);
		}

		Elements radioContainers = doc.select("#report-body td[indicator-input-type=radio]");
		for (Element radioContainer : radioContainers) {
			String val = radioContainer.select("input[checked]").val();
			radioContainer.empty().text(val);
		}

		Elements checkboxContainers = doc.select("#report-body td[indicator-input-type=checkbox]");
		for (Element checkboxContainer : checkboxContainers) {

			Elements checkeds = checkboxContainer.select("input[checked]");
			String checkedVal = "";
			for (Element checked : checkeds) {
				checkedVal += checked.val() + " ";
			}

			checkboxContainer.empty().text(checkedVal);
		}

		Element addRowBtn = doc.getElementById("#add-report-body-row-btn");
		if (addRowBtn != null) {
			addRowBtn.parent().remove();
		}

		return doc.select("#myPrintArea").html();
	}

	/**
	 * 获取Excel报表文件的区域属性.
	 * 
	 * @param excelFile excel文件
	 * @param reportTypeId 报表类型id
	 * @return
	 */
	public ReportExcelSectionVO getReportExcelSectionInfo(File excelFile, String reportTypeId) {
		ReportTypeNz reportType = indicatorSystemDao.fetch(ReportTypeNz.class, reportTypeId);
		ReportTemplateInfo reportInfo = Json.fromJson(ReportTemplateInfo.class, reportType.getReportInfo());
		ReportExcelSectionVO result = null;
		if (reportType.getDataType().intValue() == ReportStyle.CELL.getValue()) {
			result = getCellReportExcelSectionInfo(reportInfo);
		} else {
			result = getRowReportExcelSectionInfo(excelFile, reportInfo);
		}
		result.setReportTemplateInfo(reportInfo);
		return result;
	}

	/**
	 * 获取单元格式报表的Excel文件的区域信息.
	 * 
	 * @param reportType
	 */
	private ReportExcelSectionVO getCellReportExcelSectionInfo(ReportTemplateInfo reportInfo) {
		ReportExcelSectionVO result = new ReportExcelSectionVO();
		result.setTableBodyStartRow(reportInfo.getReportTableBodyStartRow());
		result.setTableBodyEndRow(reportInfo.getCellReportTableBodyEndRow());
		result.setHasReportFoot(reportInfo.getReportFoot().size() > 0);
		if (result.isHasReportFoot()) {
			result.setReportFootStartRow(reportInfo.getCellReportFootStartRow());
			result.setReportFootEndRow(reportInfo.getCellReportFootEndRow());
		}
		result.setInputInfos(getCellReportExcelInputIndicatorInfo(reportInfo));
		return result;
	}

	/***
	 * 获取单元格式报表输入项所处Excel位置信息.
	 * 
	 * @param reportInfo
	 */
	private List<ReportExcelInputInfo> getCellReportExcelInputIndicatorInfo(ReportTemplateInfo reportInfo) {
		List<ReportExcelInputInfo> inputInfos = Lists.newArrayList();

		Set<ReportCell> cells = Sets.union(reportInfo.getUniqueReportTitles(), reportInfo.getUniqueReportFoots());

		for (ReportCell cell : cells) {
			if (cell.getInputid() != null) {
				ReportExcelInputInfo reii = getReportInputExcelInfo(cell);
				if (reii != null) {
					inputInfos.add(reii);
				}
			}

		}

		return inputInfos;
	}

	private ReportExcelInputInfo getReportInputExcelInfo(ReportCell cell) {
		return getReportInputExcelInfo(cell, 0);
	}

	private ReportExcelInputInfo getReportInputExcelInfo(ReportCell cell, int rowOffset) {
		Cnd cnd = Cnd.where("id", "=", cell.getInputid()).and("type", "=", ReportInputTitle.TYPE_INPUT);
		ReportInputTitle inputTitle = indicatorSystemDao.fetch(ReportInputTitle.class, cnd);
		ReportExcelInputInfo reii = null;
		if (inputTitle != null) {
			reii = new ReportExcelInputInfo();
			reii.setAttrName(inputTitle.getAttrName());
			reii.setRowIndex(cell.getRowid() + rowOffset);
			reii.setColumnIndex(cell.getColid());
		}

		return reii;
	}

	/**
	 * 获取行式报表的Excel文件的区域信息.
	 * 
	 * @param excelFile excel文件
	 * @param reportType 报表类型
	 */
	private ReportExcelSectionVO getRowReportExcelSectionInfo(File excelFile, ReportTemplateInfo reportInfo) {
		ReportExcelSectionVO result = new ReportExcelSectionVO();
		result.setTableBodyStartRow(reportInfo.getReportTableBodyStartRow());
		result.setHasReportFoot(reportInfo.getReportFoot().size() > 0);

		// 是否在存在报表尾信息
		if (result.isHasReportFoot()) {
			ReportFooterCell markCell = reportInfo.getReportFootMarkCell();
			if (markCell == null) {
				// 无法取出鉴别表尾，数据区域为数据起始行到Excel有效的行数
				result.setHasReportFoot(false);
				result.setTableBodyEndRow(getExcelSheetRowCount(excelFile));
			} else {
				int markFotterStartRow = getRowReportFooterStartRow(excelFile, markCell);
				// 表尾标识行是否表尾起始行相等，相等表示前面无空行
				if (reportInfo.getReportFootMinStaticRow().equals(reportInfo.getReportFootMinRow())) {
					// 数据终止行
					result.setTableBodyEndRow(markFotterStartRow - 1);
					result.setReportFootStartRow(markFotterStartRow);
					result.setReportFootEndRow(markFotterStartRow + reportInfo.getReportFootRowCount() - 1);
				} else {
					// 标识行前面存在空行,表尾的起始行为空行
					int footStartRow = markFotterStartRow
							- (reportInfo.getReportFootMinStaticRow() - reportInfo.getReportFootMinRow());
					result.setTableBodyEndRow(footStartRow - 1);
					result.setReportFootStartRow(footStartRow);
					result.setReportFootEndRow(footStartRow + reportInfo.getReportFootRowCount() - 1);
				}
			}
		} else {

			result.setTableBodyEndRow(getExcelSheetRowCount(excelFile));
		}

		result.setInputInfos(getRowReportExcelInputIndicatorInfo(reportInfo, result));
		return result;
	}

	/***
	 * 获取行式报表的输入项信息
	 * 
	 * @param reportInfo
	 * @param excelSection
	 * @return
	 */
	private List<ReportExcelInputInfo> getRowReportExcelInputIndicatorInfo(ReportTemplateInfo reportInfo,
			ReportExcelSectionVO excelSection) {
		List<ReportExcelInputInfo> inputInfos = Lists.newArrayList();

		for (ReportCell cell : reportInfo.getUniqueReportTitles()) {
			if (cell.getInputid() != null) {
				ReportExcelInputInfo reii = getReportInputExcelInfo(cell);
				if (reii != null) {
					inputInfos.add(reii);
				}
			}
		}

		if (excelSection.isHasReportFoot()) {

			int footerRowOffset = excelSection.getTableBodyEndRow() - excelSection.getTableBodyStartRow();
			for (ReportCell cell : reportInfo.getUniqueReportFoots()) {
				if (cell.getInputid() != null) {
					ReportExcelInputInfo reii = getReportInputExcelInfo(cell, footerRowOffset);
					if (reii != null) {
						inputInfos.add(reii);
					}
				}
			}
		}

		return inputInfos;
	}

	/**
	 * 取出报表尾标识单元格在Excel文件中的行号.
	 * 
	 * @param excelFile excel 文件
	 * @param markCell 标识单元格
	 * @return
	 */
	private int getRowReportFooterStartRow(File excelFile, ReportFooterCell markCell) {
		Workbook wb = null;
		int rowNum = 0;
		try {
			wb = WorkbookFactory.create(excelFile);
			Sheet sheet = wb.getSheetAt(0);
			String markCellContenet = markCell.getContent().replaceAll("&nbsp;", "");
			for (org.apache.poi.ss.usermodel.Row row : sheet) {
				for (Cell cell : row) {
					if (cell != null && Cell.CELL_TYPE_STRING == cell.getCellType()) {
						String cellVal = cell.getStringCellValue().trim().replaceAll("\\s*", "");
						if (markCellContenet.equals(cellVal)) {
							return row.getRowNum();
						}
					}
				}
			}
		} catch (InvalidFormatException e) {
			throw Lang.wrapThrow(e, "Excel单元格格式错误");
		} catch (IOException e) {
			throw Lang.wrapThrow(e, "Excel文件错误");
		}
		return rowNum;
	}

	/**
	 * 获取Excel文件的有效行数.
	 * 
	 * @param excelFile
	 * @return
	 */
	private int getExcelSheetRowCount(File excelFile) {
		int rowCount = 0;
		Workbook wb = null;
		try {
			wb = WorkbookFactory.create(excelFile);
			Sheet sheet = wb.getSheetAt(0);
			rowCount = sheet.getLastRowNum();
		} catch (InvalidFormatException e) {
			throw Lang.wrapThrow(e, "Excel单元格格式错误");
		} catch (IOException e) {
			throw Lang.wrapThrow(e, "Excel文件错误");
		}
		return rowCount;
	}

	/** 报表html页面模板 */
	private final String reportExcelHtmlTemp = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\n"
			+ "xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\">\r\n"
			+ "<head>\r\n"
			+ "    <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\r\n"
			+ "    <!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name></x:Name><x:WorksheetOptions><x:Selected/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->\r\n"
			+ "    <style type=\"text/css\">\r\n"
			+ "body{\r\n"
			+ "	font-size: 12px;\r\n"
			+ "}\r\n"
			+ "\r\n"
			+ ".title {\r\n"
			+ "	font-size: 24px;\r\n"
			+ "}\r\n"
			+ " table{\r\n"
			+ "	border-collapse: collapse;\r\n"
			+ "	border-spacing: 0;\r\n"
			+ "	height: 100%;\r\n"
			+ "	table-layout:fixed\r\n"
			+ "}\r\n"
			+ "#report-body  table  th{\r\n"
			+ "	border: 0.5pt solid #000;\r\n"
			+ "	text-align: center;\r\n"
			+ "	line-height: 2.3;\r\n"
			+ "}\r\n"
			+ "\r\n"
			+ "#report-body table  tbody  td{\r\n"
			+ "	border: 0.5pt solid #000;\r\n"
			+ "	line-height: 2.3;\r\n"
			+ "	padding:0  5px 5px 5px;\r\n"
			+ "	vertical-align: middle;\r\n"
			+ "}  \r\n"
			+ "        \r\n"
			+ "    </style>\r\n"
			+ "</head>\r\n"
			+ "</html>";
}
